
import "@/css/match.scss"
import {LoadMore} from  "@/js/utils/load_more.js"
import queryString from "query-string";
import "@/js/utils/lazyload.js"

if(module.hot) {
    module.hot.accept()
 }


$(function(){
    class Mechanism{
        // 构造
        constructor(){
       
        }
        Initialization(){
           this.getData()
           
           
        }
        getData(){
            const parsed = queryString.parse(location.search);
            let _this=this;
            let laodMore=new LoadMore()
            laodMore.Initialization({
                url:API.share.organization,
                page:1,
                data:parsed,
                method:"get",
                ele:".match_list",
                success:function (e,page) {
                  if(e.rescode==0){
                    if(e.hasMore==true){
                        this.page=page+1;
                    }
                    else
                    {
                        this.page=page;
                    }
                    //精品推荐渲染
                     const renderTuiJian=function(data){
                         let code='<li><em>精品推荐</em><a href=http://mp.hippo体育.cn/article/detail/'+data.id+'>'+data.name+'</a></li>'
                         return code
                     }
                    let cli=""
                    for(var i=0;i<e.organization.orgRecommends.length;i++){
                        cli+=renderTuiJian(e.organization.orgRecommends[i])
                    }
                    $(".list_recommend ul").html("")
                    $(cli).appendTo(".list_recommend ul")
                    //渲染list
                     const renderList=function(data){
                        var html='<a class="item" href="http://mp.hippo体育.cn/article/detail/'+data.itemId+'">\
                                <img  class="lazy"  data-original='+data.pic+' />\
                                <div class="icon">\
                                    <em class="live"></em>\
                            </div>\
                                <div class="title">'+data.title+'</div>\
                                <div class="dz_dflex">\
                                    <div class="dz_flex">\
                                    '+(data.authorLabel.sourceName!=null?data.authorLabel.sourceName:"")+'\
                                          '+data.authorLabel.name+'\
                                    </div>\
                                    <div class="time">'+data.groupDate+'</div>\
                                </div>\
                            </div>\
                        </a>'
                        return html
                    }
                    let li=""
                    for(var i=0;i<e.items.length;i++){
                        li+=renderList(e.items[i])
                    }
                    //头部信息
                    $(".top img").attr("src",e.organization.icon)
                    $(".des").html(e.organization.popCount+'<span>人气</span>  /  '+e.organization.connectCount+'个<span>视频</span>')
                    $(".top .title").text(e.organization.name)
                    $(".describe p").text(e.organization.description)

                    document.title=e.organization.name
                    $(li).appendTo(this.ele)
                    $("img.lazy").lazyload({effect: "fadeIn"});
                    _this.IsOpen(e.organization.background)
                    //页面显示
                    $(".page-load").hide()
                    $(".page-body").show()

                  }
                  else
                  {
                        DZ.form.Prompt(e.resmsg,1)
                   }
                }
            })
        }
        IsOpen(url){
          
           $(".bg").attr("style","background: url("+url+") no-repeat;")
           let len= DZ.GetLength($(".describe p").text(),1)
           let text=$(".describe p").text()
           if(len>45 && len<140){
            $(".describe p").text(text.substring(0, 48)+"...")
           }
           if(len<50){
             $(".arrow").hide()
           }
           if(len>140){
             $(".bg").attr("style","")
          }
          this.actionOpen(text)
        }
        actionOpen(text){
           $(".describe .arrow").click(function(){
               let p=$(".describe p")
               if(!$(this).hasClass("up")){
                $(this).addClass("up")
                p.addClass("auto")
                $(".describe p").text(text)
               }
               else
               {
                $(this).removeClass("up")
                 p.removeClass("auto")
               }
           })
        }
    }
    var Mech = new Mechanism();
    Mech.Initialization()
})

